home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-02-19 | 29.0 KB | 841 lines | [TEXT/CWIE] |
- /*
- File: CoreSuite.c
-
- Contains: Event handlers for the core suite
-
- Written by: Greg Anderson
-
- Copyright: © 1993-1995 by Greg Anderson, all rights reserved.
-
- <29> 6/23/95 ga
- */
-
-
-
- #include "CoreSuite.h"
- #include "TransactionSuite.h"
- #include "AbstractScriptableObject.h"
- #include "MoreAEM.h"
- #include "ScriptErrors.h"
- #include "EventHandlerTable.h"
-
- #include <AERegistry.h>
- #include <ASRegistry.h>
-
- #include "Exceptions.h"
-
-
- #define keyAEUsing 'usin'
-
-
- #if 0
-
- #if GENERATINGCFM
- static RoutineDescriptor gExistsHandlerRD = BUILD_ROUTINE_DESCRIPTOR(uppAEEventHandlerProcInfo, TCoreSuite::DoExists);
- static RoutineDescriptor gGetDataHandlerRD = BUILD_ROUTINE_DESCRIPTOR(uppAEEventHandlerProcInfo, TCoreSuite::DoGetData);
- static RoutineDescriptor gSetDataHandlerRD = BUILD_ROUTINE_DESCRIPTOR(uppAEEventHandlerProcInfo, TCoreSuite::DoSetData);
- static RoutineDescriptor gGetDataSizeHandlerRD = BUILD_ROUTINE_DESCRIPTOR(uppAEEventHandlerProcInfo, TCoreSuite::DoGetDataSize);
- static RoutineDescriptor gNewElementHandlerRD = BUILD_ROUTINE_DESCRIPTOR(uppAEEventHandlerProcInfo, TCoreSuite::DoNewElement);
- static RoutineDescriptor gNumberOfElementsHandlerRD = BUILD_ROUTINE_DESCRIPTOR(uppAEEventHandlerProcInfo, TCoreSuite::DoNumberOfElements);
- static RoutineDescriptor gOpenHandlerRD = BUILD_ROUTINE_DESCRIPTOR(uppAEEventHandlerProcInfo, TCoreSuite::DoOpen);
- static RoutineDescriptor gMoveHandlerRD = BUILD_ROUTINE_DESCRIPTOR(uppAEEventHandlerProcInfo, TCoreSuite::DoMove);
-
- AEEventHandlerUPP gCommandHandlerUPP = nil;
- #endif
-
- #endif
-
- //----------------------------------------------------------------------------------------
- // TCoreSuite::InstallAEHandlers:
- //----------------------------------------------------------------------------------------
- void TCoreSuite::InstallAEHandlers(TEventHandlerTable& eventTable)
- {
- //
- // The event handler table will generate a UPP if it needs to
- //
- FailErr(eventTable.InstallHandler(kCoreEventClass, 'open', (EventHandlerProcPtr) &TCoreSuite::DoOpen, kAEOpen));
- FailErr(eventTable.InstallHandler(kCoreEventClass, kAEOpen, (EventHandlerProcPtr) &TCoreSuite::DoOpen, kAEOpen));
- FailErr(eventTable.InstallHandler(kCoreEventClass, kAEPrint, (EventHandlerProcPtr) &TCoreSuite::DoCommand, kAEPrint));
-
- // events from the core suite
-
- FailErr(eventTable.InstallHandler(kAECoreSuite, kAEDoObjectsExist, (EventHandlerProcPtr) &TCoreSuite::DoExists, 0));
- FailErr(eventTable.InstallHandler(kAECoreSuite, kAEGetData, (EventHandlerProcPtr) &TCoreSuite::DoGetData, 0));
- FailErr(eventTable.InstallHandler(kAECoreSuite, kAESetData, (EventHandlerProcPtr) &TCoreSuite::DoSetData, 0));
- FailErr(eventTable.InstallHandler(kAECoreSuite, kAEGetDataSize, (EventHandlerProcPtr) &TCoreSuite::DoGetDataSize, 0));
- FailErr(eventTable.InstallHandler(kAECoreSuite, kAECreateElement, (EventHandlerProcPtr) &TCoreSuite::DoNewElement, 0));
- FailErr(eventTable.InstallHandler(kAECoreSuite, kAECountElements, (EventHandlerProcPtr) &TCoreSuite::DoNumberOfElements, 0));
-
- FailErr(eventTable.InstallHandler(kAECoreSuite, kAEClone, (EventHandlerProcPtr) &TCoreSuite::DoMove, kAEClone));
- FailErr(eventTable.InstallHandler(kAECoreSuite, kAEDelete, (EventHandlerProcPtr) &TCoreSuite::DoCommand, kAEDelete));
- FailErr(eventTable.InstallHandler(kAECoreSuite, kAEClose, (EventHandlerProcPtr) &TCoreSuite::DoCommand, kAEClose));
- FailErr(eventTable.InstallHandler(kAECoreSuite, kAEMove, (EventHandlerProcPtr) &TCoreSuite::DoMove, kAEMove));
- FailErr(eventTable.InstallHandler(kAECoreSuite, kAESave, (EventHandlerProcPtr) &TCoreSuite::DoCommand, kAESave));
-
- #if 0
-
- #if GENERATINGCFM
- // events from the required suite
-
- gCommandHandlerUPP = NewRoutineDescriptor((ProcPtr) &TCoreSuite::DoCommand, uppAEEventHandlerProcInfo, GetCurrentISA());
- FailNil(gCommandHandlerUPP);
-
- //
- // kAEOpen is 'odoc', but we also have an 'open' event in the required suite due to
- // Finder 7.0 oddities (not needed in the Scriptable Database, but...)
- //
- FailErr(AEInstallEventHandler(kCoreEventClass, 'open', &gOpenHandlerRD, kAEOpen, false));
- FailErr(AEInstallEventHandler(kCoreEventClass, kAEOpen, &gOpenHandlerRD, kAEOpen, false));
- FailErr(AEInstallEventHandler(kCoreEventClass, kAEPrint, gCommandHandlerUPP, kAEPrint, false));
-
- // events from the core suite
-
- FailErr(AEInstallEventHandler(kAECoreSuite, kAEDoObjectsExist, &gExistsHandlerRD, 0, false));
- FailErr(AEInstallEventHandler(kAECoreSuite, kAEGetData, &gGetDataHandlerRD, 0, false));
- FailErr(AEInstallEventHandler(kAECoreSuite, kAESetData, &gSetDataHandlerRD, 0, false));
- FailErr(AEInstallEventHandler(kAECoreSuite, kAEGetDataSize, &gGetDataSizeHandlerRD, 0, false));
- FailErr(AEInstallEventHandler(kAECoreSuite, kAECreateElement, &gNewElementHandlerRD, 0, false));
- FailErr(AEInstallEventHandler(kAECoreSuite, kAECountElements, &gNumberOfElementsHandlerRD, 0, false));
-
- FailErr(AEInstallEventHandler(kAECoreSuite, kAEClone, &gMoveHandlerRD, kAEClone, false));
- FailErr(AEInstallEventHandler(kAECoreSuite, kAEDelete, gCommandHandlerUPP, kAEDelete, false));
- FailErr(AEInstallEventHandler(kAECoreSuite, kAEClose, gCommandHandlerUPP, kAEClose, false));
- FailErr(AEInstallEventHandler(kAECoreSuite, kAEMove, &gMoveHandlerRD, kAEMove, false));
- FailErr(AEInstallEventHandler(kAECoreSuite, kAESave, &gCommandHandlerUPP, kAESave, false));
-
-
- #else
- // events from the required suite
-
- FailErr(AEInstallEventHandler(kCoreEventClass, 'open', (AEEventHandlerProcPtr) &TCoreSuite::DoOpen, kAEOpen, false));
- FailErr(AEInstallEventHandler(kCoreEventClass, kAEOpen, (AEEventHandlerProcPtr) &TCoreSuite::DoOpen, kAEOpen, false));
- FailErr(AEInstallEventHandler(kCoreEventClass, kAEPrint, (AEEventHandlerProcPtr) &TCoreSuite::DoCommand, kAEPrint, false));
-
- // events from the core suite
-
- FailErr(AEInstallEventHandler(kAECoreSuite, kAEDoObjectsExist, (AEEventHandlerProcPtr) &TCoreSuite::DoExists, 0, false));
- FailErr(AEInstallEventHandler(kAECoreSuite, kAEGetData, (AEEventHandlerProcPtr) &TCoreSuite::DoGetData, 0, false));
- FailErr(AEInstallEventHandler(kAECoreSuite, kAESetData, (AEEventHandlerProcPtr) &TCoreSuite::DoSetData, 0, false));
- FailErr(AEInstallEventHandler(kAECoreSuite, kAEGetDataSize, (AEEventHandlerProcPtr) &TCoreSuite::DoGetDataSize, 0, false));
- FailErr(AEInstallEventHandler(kAECoreSuite, kAECreateElement, (AEEventHandlerProcPtr) &TCoreSuite::DoNewElement, 0, false));
- FailErr(AEInstallEventHandler(kAECoreSuite, kAECountElements, (AEEventHandlerProcPtr) &TCoreSuite::DoNumberOfElements, 0, false));
-
- FailErr(AEInstallEventHandler(kAECoreSuite, kAEClone, (AEEventHandlerProcPtr) &TCoreSuite::DoMove, kAEClone, false));
- FailErr(AEInstallEventHandler(kAECoreSuite, kAEDelete, (AEEventHandlerProcPtr) &TCoreSuite::DoCommand, kAEDelete, false));
- FailErr(AEInstallEventHandler(kAECoreSuite, kAEClose, (AEEventHandlerProcPtr) &TCoreSuite::DoCommand, kAEClose, false));
- FailErr(AEInstallEventHandler(kAECoreSuite, kAEMove, (AEEventHandlerProcPtr) &TCoreSuite::DoMove, kAEMove, false));
- FailErr(AEInstallEventHandler(kAECoreSuite, kAESave, (AEEventHandlerProcPtr) &TCoreSuite::DoCommand, kAESave, false));
- #endif
-
- #endif
-
- } // TCoreSuite::InstallAEHandlers
-
- //----------------------------------------------------------------------------------------
- // TCoreSuite::DoExists:
- //----------------------------------------------------------------------------------------
- pascal OSErr TCoreSuite::DoExists(TAEvent& ae, TAEvent& reply, long /* refCon */)
- {
- Boolean directObjectExists = true;
- OSErr err = noErr;
-
- TDescriptor objectSpecifierList;
- TTokenDescriptor directObjectToken;
- TDescriptor doesExist;
- TDescriptor offendingObject;
- TAETransaction transaction(ae, reply);
- NOREGISTER(transaction);
-
- Try
- {
- TTransactionSuite::BeginEventTransaction(transaction, kTransactionNotRequired);
-
- //
- // Try to resolve the direct object; if there is no direct object,
- // or if the direct object fails to resolve to a token, then 'exists'
- // will return 'false'
- //
- objectSpecifierList = ae.GetDescriptorParameter(keyDirectObject);
- directObjectToken = objectSpecifierList.Resolve(transaction, &offendingObject);
-
- //
- // Check to see if the resolved token really does exist
- //
- TAbstractScriptableObject* token = directObjectToken.TokenObject();
- {
- //
- // If the token claims that it does not exist, then
- // return false. Examples where this is true includes
- // the selection, which will always resolve to a token,
- // but would rather return 'false' in response to an
- // 'Exists' routine if there are no items in the selection.
- //
- if(token->Exists(transaction) == false)
- directObjectExists = false;
- }
- TTransactionSuite::EndEventTransaction(transaction);
- }
- Catch(err)
- {
- TTransactionSuite::TerminateEventTransaction(transaction);
- directObjectExists = false;
- if(err == errAENoSuchObject)
- err = noErr;
- else
- ProcessError(err, offendingObject, reply);
- }
-
- doesExist.SetBooleanData(directObjectExists);
- reply.PutResult(doesExist);
-
- doesExist.Dispose();
- directObjectToken.DisposeToken();
- objectSpecifierList.Dispose();
- offendingObject.Dispose();
-
- return err;
- } // TCoreSuite::DoExists
-
- //----------------------------------------------------------------------------------------
- // TCoreSuite::DoGetData:
- //----------------------------------------------------------------------------------------
- pascal OSErr TCoreSuite::DoGetData(TAEvent& ae, TAEvent& reply, long /* refCon */)
- {
- OSErr err = noErr;
-
- TDescriptor objectSpecifierList;
- TTokenDescriptor directObjectToken;
- TDescriptor requestedType;
- TDescriptor resultDescriptor;
- TDescriptor offendingObject;
- TAETransaction transaction(ae, reply);
- NOREGISTER(transaction);
-
- Try
- {
- TTransactionSuite::BeginEventTransaction(transaction, kTransactionNotRequired);
- objectSpecifierList = ae.GetDescriptorParameter(keyDirectObject);
- directObjectToken = objectSpecifierList.Resolve(transaction, &offendingObject);
-
- requestedType = ae.GetOptionalParameter(keyAERequestedType,typeAEList);
-
- TAbstractScriptableObject* token = directObjectToken.TokenObject();
- resultDescriptor = token->GetDataGivenListOfTypes(transaction, pContents, requestedType);
- TTransactionSuite::EndEventTransaction(transaction);
- reply.PutResult(resultDescriptor);
- }
- Catch(err)
- {
- TTransactionSuite::TerminateEventTransaction(transaction);
- ProcessError(err, offendingObject, reply);
- }
-
- requestedType.Dispose();
- resultDescriptor.Dispose();
- directObjectToken.DisposeToken();
- objectSpecifierList.Dispose();
- offendingObject.Dispose();
-
- return err;
- } // TCoreSuite::DoGetData
-
- //----------------------------------------------------------------------------------------
- // TCoreSuite::DoSetData:
- //----------------------------------------------------------------------------------------
- pascal OSErr TCoreSuite::DoSetData(TAEvent& ae, TAEvent& reply, long /* refCon */)
- {
- OSErr err = noErr;
-
- TDescriptor objectSpecifierList;
- TTokenDescriptor directObjectToken;
- TDescriptor keyData;
- TDescriptor offendingObject;
-
- TAETransaction transaction(ae, reply);
- NOREGISTER(transaction);
-
- Try
- {
- TTransactionSuite::BeginEventTransaction(transaction);
-
- objectSpecifierList = ae.GetDescriptorParameter(keyDirectObject);
- directObjectToken = objectSpecifierList.Resolve(transaction, &offendingObject);
-
- keyData = ae.GetDescriptorParameter(keyAEData);
-
- TAbstractScriptableObject* token = directObjectToken.TokenObject();
- {
- TDescriptor resolvedData;
-
- //
- // It is legal to provide an object specifier to some
- // object as the key data of a SetData command.
- // ResolveKeyData attempts to resolve the object specifier
- // in the key data, and get the best data type from it
- //
- resolvedData = token->ResolveKeyData(transaction, keyData);
-
- //
- // Often, ResolveKeyData does not need to do anything.
- // To avoid requiring it to copy the key data, our
- // convention is that if ResolveKeyData returns typeNull,
- // then we use the original keyData. Otherwise, we
- // use the result of ResolveKeyData.
- //
- if(resolvedData.IsNullDescriptor())
- token->SetData(transaction, keyData);
- else
- {
- //
- // Intense voodoo magic: If we converted an object specifier
- // into an enumeration but set data did not work, then we'll
- // try a little bit harder to make it work right the second time.
- // We assume that the translation from object specifier to enumeration
- // was in error (else set data would have worked); ergo, we should
- // try to resolve the object specifier, call get data on the
- // resulting token, and pass the result to set data.
- //
- // Only do this if the best type of the token is typeEnumeration,
- // because that is the only instance in which an object specifier
- // should be translated into an enumeration.
- //
- // See the comments in TAbstractScriptableObject::ResolveKeyData
- // for related reading.
- //
- Boolean recoverAndTryAgain = (keyData.DescriptorType() == typeObjectSpecifier) && (resolvedData.DescriptorType() == typeEnumeration) && (token->BestType(transaction, pContents) == typeEnumeration);
- Try
- {
- token->SetData(transaction, resolvedData);
- recoverAndTryAgain = false;
- }
- Catch(err)
- {
- }
-
- if(recoverAndTryAgain)
- {
- resolvedData.Dispose();
- resolvedData = token->ResolveSpecifierAndGetData(transaction, keyData);
- token->SetData(transaction, resolvedData);
- }
- }
-
- resolvedData.Dispose();
- }
-
- TTransactionSuite::EndEventTransaction(transaction);
- }
- Catch(err)
- {
- TTransactionSuite::TerminateEventTransaction(transaction);
- ProcessError(err, offendingObject, reply);
- }
-
- keyData.Dispose();
- directObjectToken.DisposeToken();
- objectSpecifierList.Dispose();
- offendingObject.Dispose();
-
- return err;
- } // TCoreSuite::DoSetData
-
- //----------------------------------------------------------------------------------------
- // TCoreSuite::DoGetDataSize:
- //----------------------------------------------------------------------------------------
- pascal OSErr TCoreSuite::DoGetDataSize(TAEvent& ae, TAEvent& reply, long /* refCon */)
- {
- OSErr err = noErr;
-
- TDescriptor objectSpecifierList;
- TTokenDescriptor directObjectToken;
- TDescriptor requestedType;
- TDescriptor resultList;
- TDescriptor offendingObject;
- long resultInteger;
- TAETransaction transaction(ae, reply);
- NOREGISTER(transaction);
-
- Try
- {
- TTransactionSuite::BeginEventTransaction(transaction, kTransactionNotRequired);
- objectSpecifierList = ae.GetDescriptorParameter(keyDirectObject);
- directObjectToken = objectSpecifierList.Resolve(transaction, &offendingObject);
-
- requestedType = ae.GetOptionalParameter(keyAERequestedType,typeAEList);
-
- TAbstractScriptableObject* token = directObjectToken.TokenObject();
-
- resultInteger = token->GetDataSizeGivenListOfTypes(transaction, pContents, requestedType);
- resultList.SetSInt32Data(resultInteger);
- TTransactionSuite::EndEventTransaction(transaction);
- reply.PutResult(resultList);
- }
- Catch(err)
- {
- TTransactionSuite::TerminateEventTransaction(transaction);
- ProcessError(err, offendingObject, reply);
- }
-
- requestedType.Dispose();
- resultList.Dispose();
- directObjectToken.DisposeToken();
- objectSpecifierList.Dispose();
- offendingObject.Dispose();
-
- return err;
- } // TCoreSuite::DoGetDataSize
-
- //----------------------------------------------------------------------------------------
- // TCoreSuite::DoNewElement:
- //----------------------------------------------------------------------------------------
- pascal OSErr TCoreSuite::DoNewElement(TAEvent& ae, TAEvent& reply, long /* refCon */)
- {
- OSErr err = noErr;
-
- TDescriptor insertionLocation;
- TTokenDescriptor insertHereToken;
- TDescriptor initialData;
- TDescriptor initialProperties;
- TDescriptor resultList;
- TDescriptor offendingObject;
-
- TAETransaction transaction(ae, reply);
- NOREGISTER(transaction);
-
- Try
- {
- TTransactionSuite::BeginEventTransaction(transaction);;
- DescType newObjectClass;
-
- newObjectClass = ae.GetDescTypeParameter(keyAEObjectClass);
- insertionLocation = ae.GetOptionalParameter(keyAEInsertHere);
- initialData = ae.GetOptionalParameter(keyASPrepositionTo);
- if(initialData.IsNullDescriptor())
- initialData = ae.GetOptionalParameter(keyAEData);
- initialProperties = ae.GetOptionalParameter(keyAEPropData);
-
- //
- // Resolve the insertion location parameter
- //
- insertHereToken = insertionLocation.Resolve(transaction, &offendingObject);
-
- TAbstractScriptableObject* token = insertHereToken.TokenObject();
- TAbstractScriptableObject* oneResult = nil;
-
- Boolean usedInitialData = false;
- Boolean usedInitialProperties = false;
-
- //
- // Give the token the new object class and its initial data
- //
- oneResult = token->CreateNewElement(transaction, newObjectClass, initialData, initialProperties, usedInitialData, usedInitialProperties);
-
- //
- // We don't expect 'oneResult' to ever come back nil;
- // if the object couldn't be created, then 'CreateNewElement'
- // should fail.
- //
- if(oneResult == nil)
- FailErr(errAEEventFailed);
-
- //
- // If create really did create something, then
- // we would like to set its initial properties
- // and return a result object specifier to the object
- // If initial properties were specified, then set them here
- //
- if((usedInitialProperties == false) && (initialProperties.DescriptorType() != typeNull))
- {
- oneResult->SetProperties(transaction, initialProperties);
- }
-
- //
- // If initial data was specified, then set it
- //
- if((usedInitialData == false) && (initialData.DescriptorType() != typeNull))
- {
- oneResult->SetData(transaction, initialData);
- }
-
- //
- // Make an object specifier for the token and add it to
- // the result list
- //
- resultList = oneResult->BuildObjectSpecifier(transaction);
- // oneResult->DisposeDesignator();
-
- TTransactionSuite::EndEventTransaction(transaction);
-
- //
- // Once all of the items are created and initialized, put the
- // result list into the reply.
- //
- reply.PutResult(resultList);
- }
- Catch(err)
- {
- TTransactionSuite::TerminateEventTransaction(transaction);
- ProcessError(err, offendingObject, reply);
- }
-
- // insertHereToken.DisposeToken();
- insertionLocation.Dispose();
- initialData.Dispose();
- initialProperties.Dispose();
- resultList.Dispose();
- offendingObject.Dispose();
-
- return err;
- } // TCoreSuite::DoNewElement
-
- //----------------------------------------------------------------------------------------
- // TCoreSuite::DoNumberOfElements:
- //----------------------------------------------------------------------------------------
- pascal OSErr TCoreSuite::DoNumberOfElements(TAEvent& ae, TAEvent& reply, long /* refCon */)
- {
- OSErr err = noErr;
-
- TDescriptor objectSpecifierList;
- TTokenDescriptor directObjectToken;
- TDescriptor result;
- TDescriptor offendingObject;
- TAETransaction transaction(ae, reply);
- NOREGISTER(transaction);
-
- long theCount = 0;
-
- Try
- {
- TTransactionSuite::BeginEventTransaction(transaction, kTransactionNotRequired);
- objectSpecifierList = ae.GetDescriptorParameter(keyDirectObject);
- directObjectToken = objectSpecifierList.Resolve(transaction);
-
- //
- // Get the type of object to count. If no type was
- // specified, assume typeWildCard.
- //
- DescType classToCount = ae.GetDescTypeParameter(keyAEObjectClass);
- if(!classToCount)
- classToCount = typeWildCard;
-
- TAbstractScriptableObject* token = directObjectToken.TokenObject();
- {
- theCount += token->CountElements(transaction, classToCount);
- }
-
- TTransactionSuite::EndEventTransaction(transaction);
- result.SetSInt32Data(theCount);
- reply.PutResult(result);
- }
- Catch(err)
- {
- TTransactionSuite::TerminateEventTransaction(transaction);
- ProcessError(err, offendingObject, reply);
- }
-
- result.Dispose();
- directObjectToken.DisposeToken();
- objectSpecifierList.Dispose();
- offendingObject.Dispose();
-
- return err;
- } // TCoreSuite::DoNumberOfElements
-
- //----------------------------------------------------------------------------------------
- // TCoreSuite::DoCommand:
- //----------------------------------------------------------------------------------------
- pascal OSErr TCoreSuite::DoCommand(TAEvent& ae, TAEvent& reply, long refCon)
- {
- OSErr err = noErr;
-
- TDescriptor objectSpecifierList;
- TTokenDescriptor directObjectToken;
- TDescriptor resultList;
- TDescriptor noOptionalParameters;
- TDescriptor resultDescriptor;
- TDescriptor offendingObject;
- TAETransaction transaction(ae, reply);
- NOREGISTER(transaction);
-
- Try
- {
- TTransactionSuite::BeginEventTransaction(transaction);;
- objectSpecifierList = ae.GetOptionalParameter(keyDirectObject);
- directObjectToken = objectSpecifierList.Resolve(transaction, &offendingObject);
-
- TAbstractScriptableObject* token = directObjectToken.TokenObject();
- {
- resultDescriptor = token->AECommandDispatch(transaction, refCon);
- resultList.AppendListAndDispose(resultDescriptor);
- resultDescriptor.ClearDescriptor();
- }
- TTransactionSuite::EndEventTransaction(transaction);
- reply.PutResult(resultList);
- }
- Catch(err)
- {
- TTransactionSuite::TerminateEventTransaction(transaction);
- resultDescriptor.Dispose();
- ProcessError(err, offendingObject, reply);
- }
-
- objectSpecifierList.Dispose();
- directObjectToken.DisposeToken();
- resultList.Dispose();
- offendingObject.Dispose();
-
- return err;
- } // TCoreSuite::DoCommand
-
- //----------------------------------------------------------------------------------------
- // TCoreSuite::DoOpen:
- //----------------------------------------------------------------------------------------
- pascal OSErr TCoreSuite::DoOpen(TAEvent& ae, TAEvent& reply, long refCon)
- {
- OSErr err = noErr;
-
- TDescriptor objectSpecifierList;
- TTokenDescriptor directObjectToken;
- TDescriptor resultList;
- TDescriptor noOptionalParameters;
- TTokenDescriptor appToOpenWith;
- TDescriptor resultDescriptor;
- TDescriptor offendingObject;
- TAETransaction transaction(ae, reply);
- NOREGISTER(transaction);
-
- Try
- {
- objectSpecifierList = ae.GetDescriptorParameter(keyDirectObject);
-
- TTransactionSuite::BeginEventTransaction(transaction);;
-
- //
- // It's legal to say "open alias..." (in fact, common).
- // In that case, send the open straight to the null container.
- //
- // Per convention, though, the Finder always sends a list
- // of alias or FSSpec descriptors, even if only one item
- // was opened.
- //
- if((objectSpecifierList.DescriptorType() == typeAlias) || (objectSpecifierList.DescriptorType() == typeFSS) || (objectSpecifierList.DescriptorType() == typeAEList))
- {
- directObjectToken = CreateNullContainerToken();
- TAbstractScriptableObject* token = directObjectToken.TokenObject();
- resultList = token->AECommand(transaction, refCon);
- }
- //
- // If the direct object isn't an alias/fsspec
- // then resolve and process it as usual
- //
- else
- {
- directObjectToken = objectSpecifierList.Resolve(transaction, &offendingObject);
- TAbstractScriptableObject* token = directObjectToken.TokenObject();
- {
- resultDescriptor = token->AECommand(transaction, refCon);
- resultList.AppendListAndDispose(resultDescriptor);
- resultDescriptor.ClearDescriptor();
- }
- }
-
- TTransactionSuite::EndEventTransaction(transaction);
- reply.PutResult(resultList);
- }
- Catch(err)
- {
- TTransactionSuite::TerminateEventTransaction(transaction);
- resultDescriptor.Dispose();
- ProcessError(err, offendingObject, reply);
- }
-
- objectSpecifierList.Dispose();
- directObjectToken.DisposeToken();
- resultList.Dispose();
- appToOpenWith.DisposeToken();
- offendingObject.Dispose();
-
- return err;
- } // TCoreSuite::DoOpen
-
- #if 0
-
- //
- // A more generic version of 'DoOpen,' for applications that can resolve
- // every object specifier that the Finder can:
- //
-
- //----------------------------------------------------------------------------------------
- // TCoreSuite::DoOpen:
- //----------------------------------------------------------------------------------------
- pascal OSErr TCoreSuite::DoOpen(TAEvent& ae, TAEvent& reply, long refCon)
- {
- OSErr err = noErr;
-
- TDescriptor objectSpecifierList;
- TTokenDescriptor directObjectToken;
- TDescriptor resultList;
- TDescriptor noOptionalParameters;
- TDescriptor openUsing;
- TTokenDescriptor appToOpenWith;
- TDescriptor resultDescriptor;
- TAETransaction transaction(ae, reply);
- NOREGISTER(transaction);
-
- Try
- {
- TTransactionSuite::BeginEventTransaction(transaction);;
- objectSpecifierList = ae.GetDescriptorParameter(keyDirectObject);
- directObjectToken = objectSpecifierList.Resolve(transaction);
- openUsing = ae.GetOptionalParameter(keyAEUsing);
-
- //
- // If there is an 'open using' parameter, then send the
- // open command to it; the optional parameter is the
- // list of documents to open
- //
- if(openUsing.DescriptorType() != typeNull)
- {
- appToOpenWith = openUsing.Resolve(transaction, &offendingObject);
-
- TAbstractScriptableObject* token = appToOpenWith.TokenObject();
- {
- resultDescriptor = token->AECommand(transaction, ae, reply, refCon, directObjectToken.TokenObject());
- resultList.AppendListAndDispose(resultDescriptor);
- resultDescriptor.ClearDescriptor();
- }
- }
- //
- // If there is no 'open using' parameter, then this
- // command behaves just like "::DoCommand"
- //
- else
- {
- TAbstractScriptableObject* token = directObjectToken.TokenObject();
- {
- resultDescriptor = token->AECommand(transaction, ae, reply, refCon);
- resultList.AppendListAndDispose(resultDescriptor);
- resultDescriptor.ClearDescriptor();
- }
- }
- TTransactionSuite::EndEventTransaction(transaction);
- reply.PutResult(resultList);
- }
- Catch(err)
- {
- TTransactionSuite::TerminateEventTransaction(transaction);
- resultDescriptor.Dispose();
- ProcessError(err, offendingObject, reply);
- }
-
- objectSpecifierList.Dispose();
- directObjectToken.DisposeToken();
- resultList.Dispose();
- openUsing.Dispose();
- appToOpenWith.DisposeToken();
-
- return err;
- } // TCoreSuite::DoOpen
-
- #endif
-
- //----------------------------------------------------------------------------------------
- // TCoreSuite::DoMove:
- //----------------------------------------------------------------------------------------
- pascal OSErr TCoreSuite::DoMove(TAEvent& ae, TAEvent& reply, long refCon)
- {
- OSErr err = noErr;
-
- TDescriptor objectSpecifierList;
- TTokenDescriptor directObjectToken;
- TDescriptor resultList;
- TDescriptor noOptionalParameters;
- TDescriptor destinationObjectSpecifier;
- TDescriptor insertionLocation;
- TTokenDescriptor destinationObjectToken;
- TDescriptor resultDescriptor;
- TDescriptor offendingObject;
- TAETransaction transaction(ae, reply);
- NOREGISTER(transaction);
-
- Try
- {
- TTransactionSuite::BeginEventTransaction(transaction);;
- objectSpecifierList = ae.GetDescriptorParameter(keyDirectObject);
- directObjectToken = objectSpecifierList.Resolve(transaction, &offendingObject);
- insertionLocation = ae.GetOptionalParameter(keyAEInsertHere);
-
- if(insertionLocation.IsNullDescriptor() && (refCon == kAEClone))
- {
- TAbstractScriptableObject* token = directObjectToken.TokenObject();
- {
- resultDescriptor = token->AECommandDispatch(transaction, kAEDuplicate);
- resultList.AppendListAndDispose(resultDescriptor);
- resultDescriptor.ClearDescriptor();
- }
- }
- else
- {
- //
- // the keyAEInsertHere could be either an object specifier or
- // a typeInsertionLoc (which contains an object specifier and
- // an enumerated position--before, after, etc.). There is no
- // automatic conversion between a typeInsertionLoc and Object
- // specifiers, so we must be prepared to accept either.
- //
- if(insertionLocation.DescriptorType() != typeObjectSpecifier)
- {
- //
- // At this point we are assuming that the object
- // stored in 'keyAEInsertHere' is of type typeInsertionLoc.
- // If it isn't, then the call to 'GetDescriptorParameter' will fail.
- //
- destinationObjectSpecifier = insertionLocation.GetDescriptorParameter(keyAEObject,typeObjectSpecifier);
- insertionLocation.Dispose();
- }
- //
- // If keyAEInsert here is not a typeInsertionLoc, then just
- // have the destination object specifier adopt it
- //
- else
- {
- destinationObjectSpecifier.AdoptDescriptor(insertionLocation);
- insertionLocation.ClearDescriptor();
- }
- destinationObjectToken = destinationObjectSpecifier.Resolve(transaction, &offendingObject);
-
- //
- // In reality, our code will flail and fail if there is more than one
- // destination for a move (since the source will no longer exist by
- // the time that the second destination gets the event). It is
- // legal to have multiple destinations for a copy, though, so we'll
- // leave the loop here and just allow multiple moves to fail naturally.
- //
- TAbstractScriptableObject* token = destinationObjectToken.TokenObject();
- {
- resultDescriptor = token->AECommand(transaction, refCon, directObjectToken.TokenObject());
- resultList.AppendListAndDispose(resultDescriptor);
- resultDescriptor.ClearDescriptor();
- }
- }
- TTransactionSuite::EndEventTransaction(transaction);
- reply.PutResult(resultList);
- }
- Catch(err)
- {
- TTransactionSuite::TerminateEventTransaction(transaction);
- resultDescriptor.ClearDescriptor();
- ProcessError(err, offendingObject, reply);
- }
-
- objectSpecifierList.Dispose();
- directObjectToken.DisposeToken();
- resultList.Dispose();
- insertionLocation.Dispose();
- destinationObjectSpecifier.Dispose();
- destinationObjectToken.DisposeToken();
- offendingObject.Dispose();
-
- return err;
- } // TCoreSuite::DoMove
-